<?php
class ModelSaleRechargeablecard extends Model {


    public function getTotalrechargeablecards() {
        return $this->db->queryOne("SELECT COUNT(*) AS total FROM  @@rechargeablecard");
    }

    public function getRechargeablecards($filter = null) {
        $sql = "SELECT c.cardNumber,c.cardCode,c.cardAmount,c.cardStatus,c.cardCustomer,c.cardDate FROM  @@rechargeablecard c";

        if ($filter) {
            $sql .= $filter->sort('c.cardDate', 'DESC');
            $sql .= $filter->limit();
        }

        $query = $this->db->query($sql);

        return $query->rows;
    }

	public function getRechargeablecard($cardNumber) {
      	return $this->db->queryOne("SELECT DISTINCT * FROM  @@rechargeablecard WHERE cardNumber= " . $cardNumber);
	}


	public function editRechargeablecard($cardNumber, $data) {
		$data['cardDate'] = $GLOBALS['V5_NOW'];
		$this->db->update('rechargeablecard', $data, array('cardNumber' => $cardNumber));
	}


	public function addRechargeablecard($data) {
		$data['cardDate'] = $GLOBALS['V5_NOW'];
		$this->db->insert('rechargeablecard', $data);
	}

   public function deleteRechargeablecard($cardNumber){
       $this->db->query("DELETE FROM  @@rechargeablecard WHERE cardNumber = ".$cardNumber);
   }

   public function getCard_prefix(){
       return $this->db->queryOne("SELECT DISTINCT * FROM  @@rechargeablecard_prefix WHERE ID= 0");
   }

   public function setCard_prefix($card_prefix){
       $data['card_prefix']=$card_prefix+1;
       $this->db->update('rechargeablecard_prefix', $data, array('ID' => 0));
   }

}
?>